﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
using System.Xml.Serialization;

namespace ConsoleApplication1
{
    //class Program
    //{
    //    static void Main(string[] args)
    //    {
    //        IRunner runner = new Runner();
    //        runner = new RunnerWithJet(runner);
    //        runner.Run();
    //        Console.ReadLine();
    //    }
    //}


    public interface IRunner
    {
        void Run();
    }

    public class Runner : IRunner
    {
        public void Run()
        {
            Console.WriteLine("运动员跑步：动作很潇洒" + "\n");
        }
    }

    public class RunnerWithJet : IRunner
    {
        private IRunner runner;
        public RunnerWithJet(IRunner _runner)
        {
            this.runner = _runner;
        }
        public void Run()
        {
            Console.Write("加快运动员的速度：为运动员增加喷气装置" + "\n");
            this.runner.Run();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Program t = new Program();
            // Read a purchase order.
            t.DeserializeObject("F://workstation//visual studio 2010//Projects//ConsoleApplication1//ConsoleApplication1//simple.xml");
        }


        private void DeserializeObject(string filename)
        {
            Console.WriteLine("Reading with Stream");
            // Create an instance of the XmlSerializer.
            XmlSerializer serializer =
            new XmlSerializer(typeof(OrderedItem));
            // Reading the XML document requires a FileStream.
            Stream reader = new FileStream(filename, FileMode.Open);

            // Declare an object variable of the type to be deserialized.
            OrderedItem i;

            // Call the Deserialize method to restore the object's state.
            i = (OrderedItem)serializer.Deserialize(reader);

            // Write out the properties of the object.
            Console.Write(
            i.ItemName + "\t" +
            i.Description + "\t" +
            i.UnitPrice + "\t" +
            i.Quantity + "\t" +
            i.LineTotal);

            Console.Read();
        }



    }

    [Serializable]
    public class OrderedItem
    {
       
        public string ItemName;
       
        public string Description;
        
        public decimal UnitPrice;
        
        public int Quantity;
        
        public decimal LineTotal;
        // A custom method used to calculate price per item.
        public void Calculate()
        {
            LineTotal = UnitPrice * Quantity;
        }
    }

    class SimpleClass
    {
        // Static variable that must be initialized at run time.
        static readonly long baseline;

        // Static constructor is called at most one time, before any
        // instance constructor is invoked or member is accessed.
        static SimpleClass()
        {
            baseline = DateTime.Now.Ticks;
        }
    }
}
